package com.sn.task;

import com.sn.util.Capture;
import com.sn.net.Server;
import lombok.AllArgsConstructor;

import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @Author: songbiao
 */
@AllArgsConstructor
public class UdpSendTask implements Runnable {

    private Capture capture;
    private Server server;

    @Override
    public void run() {
        try {
            while (true) {
                byte[] data = capture.capture();
                if (data != null) {
                    server.sendData(Server.clients, data);
                } else {
                    TimeUnit.MILLISECONDS.sleep(500);
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
